<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 2015/1/30
 * Use : ...
 * File: AssetPublish.php
 */

namespace ulue\parts\asset;

use ulue\libs\traits\TraitJsonFormat;
use ulue\libs\traits\TraitGetOption;
use ulue\core\ioc\Container;

class AssetPublish
{
    /**
     * @var AssetManager
     */
    protected $asset;

    protected $enabled = false;

    use TraitGetOption;
    use TraitJsonFormat;

    public function __construct(array $options=[])
    {
        // $this->asset   = $asset ?: \Ioc::get('app.asset');
        $this->options = $options;
        $this->enabled = (bool) $this->getOption('enabled');
    }

    public function execute()
    {
        if (!$this->enabled) {
            return true;
        }

        $name = $this->getOption('name');
        $path = $this->getOption('path');
        $path = \Ulue::resolveAlias($path);

        if (is_dir($path)) {
            # code...
        } else
        {
            $assetPath  = $path. '/resources/staic';
            $josnFile   = $path. '/resources/autoPublish.json';

            $this->parseJsonFile($josnFile);
        }

    }

    public function parseJsonFile($file)
    {

        if (!file_exists($file)) {
            return false;
            // throw new \DNotFoundException("发布资源失败！没有找到或不存在资源{$file}");
        }

        $jsonArr = static::loadFile($file);

        de($jsonArr);
    }

}// end class AssetPublish